{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2023-11-01T01:52:17.726076Z",
     "start_time": "2023-11-01T01:52:17.712038700Z"
    }
   },
   "outputs": [],
   "source": [
    "import torch\n",
    "import torch.nn as nn\n",
    "from torchvision import datasets,transforms\n",
    "import matplotlib.pyplot as plt\n",
    "import torchvision"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "data_trainsforms = {\n",
    "    'train':transforms.Compose([\n",
    "        transforms.Resize(230),\n",
    "        transforms.CenterCrop(224),\n",
    "        transforms.RandomHorizontalFlip(),\n",
    "        transforms.ToTensor(),\n",
    "        transforms.Normalize((0.5,0.5,0.5),(0.5,0.5,0.5))\n",
    "    ]),\n",
    "    'test':transforms.Compose([\n",
    "        transforms.Resize(230),\n",
    "        transforms.CenterCrop(224),\n",
    "        transforms.ToTensor(),\n",
    "        transforms.Normalize((0.5,0.5,0.5),(0.5,0.5,0.5))\n",
    "    ])\n",
    "}\n",
    "\n",
    "data_path = '../data2/p1ch7'\n",
    "cifar10 = datasets.CIFAR10(data_path,download=False,transform=data_trainsforms['train'])\n",
    "cifar10_val = datasets.CIFAR10(data_path,download=False,transform=data_trainsforms['test'])\n",
    "\n",
    "# 抽取其中的鸟和飞机\n",
    "label_map = {0:0,2:1}\n",
    "class_names = ['飞机','鸟']\n",
    "cifar2 = [(img,label_map[label])for img,label in cifar10 if label in [0,2]]\n",
    "cifar2_val = [(img,label_map[label])for img,label in cifar10_val if label in [0,2]]"
   ],
   "metadata": {
    "collapsed": false,
    "is_executing": true,
    "ExecuteTime": {
     "start_time": "2023-11-01T02:08:43.195141200Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "cifar2_loader = torch.utils.data.DataLoader(cifar2,batch_size=64,shuffle=True)\n",
    "cifar2_val_loader = torch.utils.data.DataLoader(ci)"
   ],
   "metadata": {
    "collapsed": false
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
